/*
 * @Date: 2019-07-29 13:34:27
 * @Description: vue指令 - 设置元素高度，跟随window.resize
 */

var framespr = {
    install: function (Vue, options) {
        var elCache,
            valueCache;

        function handler(e) {
            var h = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - valueCache;
            elCache.style.height = h + 'px';
        }

        Vue.directive('framespr', {
            inserted: function (el, binding, vnode, oldVnode) {
                var h = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - binding.value;
                el.style.height = h + 'px';
                el.style.overflow = 'auto';
                elCache = el;
                valueCache = binding.value;
                window.addEventListener('resize', handler);
            },
            componentUpdated: function (el, binding, vnode, oldVnode) {},
            unbind: function (el, binding, vnode, oldVnode) {
                window.removeEventListener('resize', handler);
            }
        });
    }
};

module.exports = framespr;